//设置初始值
export const initState= {
    info:sessionStorage.getItem("info")?JSON.parse(sessionStorage.getItem("info")):{}
}
//修改
export const reducer = (state,action)=>{
    switch(action.type){
        case "changeInfo":
        return {
            ...state,
            info:action.info
        }
        default:
            return state
    }
}
//action
export const actions={
    changeInfo:(info,history)=>{
        if(info.token){
            sessionStorage.setItem("info",JSON.stringify(info))
            sessionStorage.setItem("islogin",1)

        }else{
            sessionStorage.removeItem("info")
            sessionStorage.removeItem("islogin")
            history.push("/login")
        }
        return {type:"changeInfo",info}
    }
}